<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目专辑关系列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="roleKey" name="roleKey" th:value="${roleKey}">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>专辑id：</p>
                                <input type="text" name="cid"/>
                            </li>
                            <li>
                                <p>专辑名称：</p>
                                <input type="text" name="title"/>
                            </li>
                            <li>
                                <p>授权方：</p>
                                <select id="authorizerId" name="authorizerId">
                                    <option value="">所有</option>
                                    <option th:each="authorizer : ${authorizerList}" th:text="${authorizer.shortName}" th:value="${authorizer.authorizerId}"></option>
                                </select>
                            </li>
                            <li>
                                <p>分类：</p>
                                <select id="classId" name="classId">
                                    <option value="">所有</option>
                                    <option th:each="classification : ${classificationList}" th:text="${classification['className']}" th:value="${classification['classId']}" th:field="*{classification.classId}"></option>
                                </select>
                            </li>
                            <li>
                                <p>状态：</p>
                                <select name="state">
                                    <option value="">所有</option>
                                    <option value="0">待出库</option>
                                    <option value="1">可出库</option>
                                    <option value="2">已出库</option>
                                    <option value="3">已上线</option>
                                    <option value="4">已下线</option>
                                    <option value="-1">不可上线</option>
                                </select>
                            </li>
                            <li class="select-time">
                                <p>上线时间：</p>
                                <input type="text" class="time-input" id="beginOnlineTime" placeholder="开始时间" name="params[beginOnlineTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endOnlineTime" placeholder="结束时间" name="params[endOnlineTime]"/>
                            </li>
                            <!--<li class="select-time">-->
                                <!--<p>下线时间：</p>-->
                                <!--<input type="text" class="time-input" id="beginOfflineTime" placeholder="开始时间" name="params[beginOfflineTime]"/>-->
                                <!--<span>-</span>-->
                                <!--<input type="text" class="time-input" id="endOfflineTime" placeholder="结束时间" name="params[endOfflineTime]"/>-->
                            <!--</li>-->
                            <li>
                                <p>项目：</p>
                                <select id="itemId" name="itemId">
                                    <div th:switch="${#lists.size(itemList)}">
                                        <p th:case="'1'"></p>
                                        <p th:case="*">
                                            <option value="">所有</option>
                                        </p>
                                    </div>
                                    <option th:each="item : ${itemList}" th:text="${item['name']}" th:value="${item['itemId']}" th:field="*{item.itemId}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="media:itemAlbum:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info multiple disabled" onclick="outStockAll(2)" shiro:hasPermission="media:itemAlbum:outStock">
                    <i class="fa fa-plus"></i> 批量出库
                </a>
                <a class="btn btn-success multiple disabled" onclick="operateAll(1,'可上线')" shiro:hasPermission="media:itemAlbum:edit" style="margin-left:4px;border-color:#55edac;background-color:#55edac;">
                    <i class="fa fa-check"></i> 批量可上线
                </a>
                <a class="btn btn-danger multiple disabled" onclick="operateAll(-1,'可上线')" shiro:hasPermission="media:itemAlbum:edit">
                    <i class="fa fa-remove"></i> 批量不可上线
                </a>
                <a class="btn btn-primary multiple disabled" onclick="operateAll(3,'上线')" shiro:hasPermission="media:itemAlbum:edit">
                    <i class="fa fa-angle-double-up"></i> 批量上线
                </a>
                <a class="btn btn-danger multiple disabled" onclick="operateAll(4,'下线')" shiro:hasPermission="media:itemAlbum:edit">
                    <i class="fa fa-angle-double-down"></i> 批量下线
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('media:itemAlbum:edit')}]];
        var outStockFlag = [[${@permission.hasPermi('media:itemAlbum:outStock')}]];
        var removeFlag = [[${@permission.hasPermi('media:itemAlbum:remove')}]];
        var prefix = ctx + "media/itemAlbum";

        $(function() {
            var options = {
                url: prefix + "/list",
                editUrl: prefix + "/edit",
                outStockUrl: prefix + "/outStock",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "项目专辑关系",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '主键',
                    visible: false
                },
                {
                    field : 'albumId',
                    title : '专辑ID'
                },
                {
                    field : 'title',
                    title : '名称'
                },
                {
                    field : 'className',
                    title : '分类',
                    formatter: function(value, row, index) {
                        return '<span class="badge badge-info"> '+ value + '</span>';
                    }
                },
                {
                    field : 'authorizerName',
                    title : '授权方',
                    formatter: function(value, row, index) {
                        return '<span class="badge badge-secondary"> '+ value + '</span>';
                    }
                },
                {
                    field : 'itemName',
                    title : '项目'
                },
                {
                    field : 'state', 
                    title : '状态',
                    formatter: function(value, row, index) {
                        if (value == '0') {
                            return '<span class="badge badge-warning-light">待出库</span>';
                        } else if (value == '1') {
                            return '<span class="badge badge-success" style="margin-left:4px;border-color:#55edac;background-color:#55edac;">可出库</span>';
                        }else if (value == '-1'){
                            return '<span class="badge badge-danger">不可上线</span>';
                        }else if (value == '2'){
                            return '<span class="badge badge-info">已出库</span>';
                        }else if (value == '3'){
                            return '<span class="badge badge-primary">已上线</span>';
                        }else if (value == '4'){
                            return '<span class="badge badge-danger">已下线</span>';
                        }
                    }
                },
                {
                    field : 'createBy',
                    title : '推荐人',
                    visible: false
                },
                {
                    field : 'createTime',
                    title : '推荐时间',
                    sortable: true
                },
                {
                    field : 'outstockTime', 
                    title : '出库时间',
                    sortable: true
                },
                {
                    field : 'onlineTime', 
                    title : '上线时间',
                    sortable: true
                },
                {
                    field : 'offlineTime', 
                    title : '下线时间',
                    sortable: true
                },
                {
                    field : 'operateReason',
                    title : '操作原因',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="itemAlbumOperateLogList(\'' + row.id + '\')" style="margin-left:4px;border-color:#aa55ed;background-color:#aa55ed;"><i class="fa fa-inbox"></i>操作详情</a>');
                        var operateName1;
                        var state1;
                        var operateName2;
                        var state2;
                        //待出库
                        if (row.state == 0){
                            operateName1 = "可上线";
                            state1 = 1;
                            operateName2 = "不可上线";
                            state2 = -1;
                        //可出库
                        }else if (row.state == 1){
                            operateName1 = "出库";
                            state1 = 2;
                        //已出库
                        }else if (row.state == 2){
                            operateName1 = "上线";
                            state1 = 3;
                        //已上线
                        }else if (row.state == 3){
                            operateName1 = "下线";
                            state1 = 4;
                        //已下线
                        }else if (row.state == 4){
                            operateName1 = "上线";
                            state1 = 3;
                            operateName2 = "重新可上线";
                            state2 = 11;
                        //不可上线
                        }else if (row.state == -1) {
                            operateName1 = "重新可上线";
                            state1 = 11;
                        }

                        if (row.state == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + ' " href="javascript:void(0)" onclick="operate(\'' + row.id  + '\',\'' + state1  + '\', \'' + operateName1  + '\')" style="margin-left:4px;border-color:#55edac;background-color:#55edac;"><i class="fa fa-check"></i>' + operateName1 + '</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + ' " href="javascript:void(0)" onclick="operate(\'' + row.id  + '\',\'' + state2  + '\', \'' + operateName2  + '\')"><i class="fa fa-remove"></i>' + operateName2 + '</a> ');
                        }else if (row.state == 4){
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + ' " href="javascript:void(0)" onclick="operate(\'' + row.id  + '\',\'' + state1  + '\', \'' + operateName1  + '\')"><i class="fa fa-angle-double-up"></i>' + operateName1 + '</a> ');
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + ' " href="javascript:void(0)" onclick="operate(\'' + row.id  + '\',\'' + state2  + '\', \'' + operateName2  + '\')"><i class="fa fa-refresh"></i>' + operateName2 + '</a> ');
                        }else if(row.state == 1){
                            actions.push('<a class="btn btn-info btn-xs ' + outStockFlag + '" href="javascript:void(0)" onclick="outStock(\'' + row.id + '\', \'' + state1 + '\')"><i class="fa fa-plus"></i>' + operateName1 + '</a>');
                        }else if(row.state == 2){
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="operate(\'' + row.id  + '\',\'' + state1  + '\', \'' + operateName1  + '\')"><i class="fa fa-angle-double-up"></i>' + operateName1 + '</a> ');
                        }else if(row.state == 3){
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="operate(\'' + row.id  + '\',\'' + state1  + '\', \'' + operateName1  + '\')"><i class="fa fa-angle-double-down"></i>' + operateName1 + '</a> ');
                        }else if(row.state == -1){
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + ' " href="javascript:void(0)" onclick="operate(\'' + row.id  + '\',\'' + state1  + '\', \'' + operateName1  + '\')"><i class="fa fa-refresh"></i>' + operateName1 + '</a> ');
                        }
//                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除推荐</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        // 单条操作
        function operate(id,state,operateName) {
            var auditConfirm = "确认要" + operateName + "该条数据吗";
            $.modal.confirm(auditConfirm, function() {
                if (state == 3){
                    $.modal.open("上线名称", prefix + "/operateReason/" + id + "/" + state,400,250);
                }else if (state == -1){
                    $.modal.open("不可上线原因", prefix + "/operateReason/" + id + "/" + state,400,250);
                }else if (state == 4){
                    $.modal.open("下线原因", prefix + "/operateReason/" + id + "/" + state,400,250);
                }else {
                    var url = $.table._option.editUrl;
                    var data = { "ids": id, "state": state};
                    $.operate.submit(url, "post", "json", data);
                }
            });
        }

        // 批量操作
        function operateAll(state,operateName) {
            var auditConfirm = "确认要" + operateName + "所选数据吗";
            var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm(auditConfirm, function() {
                if (state == 3){
                    $.modal.open("上线名称", prefix + "/operateReason/" + rows.join() + "/" + state,400,250);
                }else if (state == -1){
                    $.modal.open("不可上线原因", prefix + "/operateReason/" + rows.join() + "/" + state,400,250);
                }else if (state == 4){
                    $.modal.open("下线原因", prefix + "/operateReason/" + rows.join() + "/" + state,400,250);
                }else {
                    var url = $.table._option.editUrl;
                    var data = { "ids": rows.join(),"state": state };
                    $.operate.submit(url, "post", "json", data);
                }
            });
        }

        // 出库
        function outStock(id,state) {
            var auditConfirm = "确认要出库该条数据吗";
            $.modal.confirm(auditConfirm, function() {
                var url = $.table._option.outStockUrl;
                var data = { "ids": id, "state": state };
                $.operate.submit(url, "post", "json", data);
            });
        }

        // 批量出库
        function outStockAll(state) {
            var auditConfirm = "确认要出库所选数据吗";
            var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm(auditConfirm, function() {
                var url = $.table._option.outStockUrl;
                var data = { "ids": rows.join(),"state": state };
                $.operate.submit(url, "post", "json", data);
            });
        }

        //操作日志详情列表
        function itemAlbumOperateLogList(itemAlbumId) {
            var url = ctx + 'media/itemAlbumOperateLog?itemAlbumId=' + itemAlbumId;
            $.modal.open("操作详情", url);
        }
    </script>
</body>
</html>